package de.tabuma.pm.externalcontent.view;

import de.tabuma.lib.tabumaview;
import de.tabuma.pm.*;
import de.tabuma.pm.externalproject.entity.*;
import de.tabuma.pm.externalcontent.entity.*;
import java.io.PrintWriter;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
 *
 * @author alefen
 */
public class view extends tabumaview {

    public view(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    @Override
    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        String externalProjectName = "external Project";
        String save = "save";
        String noLoginNeeded = "no login needed";
        String contentUrl = "content url";

        ExternalContent externalContent = (ExternalContent) request.getAttribute(constants.externalContent);


        out.println(this.getFormBeginn(constants.ProjectNavigationA));

        out.println(this.getHiddenAsAttribute());

        out.println("<div class=\"cols\">");
        out.println("<div class=\"col1\">");
        out.println("<div class=\"col1_head\">"+externalProjectName+"</div>");
        out.println("<div class=\"col1_content\">");
        out.println("<select name=\""+constants.externalProjectId+"\">");
        out.println("<option value=\"0\">"+noLoginNeeded+"</option>");
        List<ExternalProject> epList = (List<ExternalProject>) request.getAttribute(constants.ExternalProjectList);
        for(int i=0;i<epList.size();i++) {
            ExternalProject ep = epList.get(i);
            if(externalContent!=null) {
                if(externalContent.getExternProjectId()==ep.getId().intValue()) {
                    out.println("<option value=\""+ep.getId().intValue()+"\" selected>"+ep.getName()+"</option>");
                }
                else {
                    out.println("<option value=\""+ep.getId().intValue()+"\">"+ep.getName()+"</option>");
                }
            }
            else {
                out.println("<option value=\""+ep.getId().intValue()+"\">"+ep.getName()+"</option>");
            }
        }
        out.println("</select>");
        out.println("</div>");
        out.println("</div>");
        out.println("<div class=\"col2\">");
        out.println("<div class=\"col2_head\"></div>");
        out.println("<div class=\"col1_content\"></div>");
        out.println("</div>");
        out.println("<div class=\"col1\">");
        out.println("<div class=\"col1_head\">"+contentUrl+"</div>");
        out.println("<div class=\"col1_content\">");
        out.println("<input type=\"text\" name=\""+constants.externalContentUrl+"\" value=\"" + (externalContent!=null ? externalContent.getUrl() : "") + "\"/>");
        out.println("</div>");
        out.println("</div>");
        out.println("<div class=\"col2\">");
        out.println("<div class=\"col2_head\"></div>");
        out.println("<div class=\"col1_content\"></div>");
        out.println("</div>");
        out.println("</div>");
        out.println("<input type=\"hidden\" name=\""+constants.externalContentUpdate+"\" value=\"true\"/>");
        out.println("<p><input type=\"submit\" name=\""+constants.next+"\" value=\""+save+"\" class=\"button\"/></p>");

        out.println(this.getFormEnd());

    }
}